/*
 * @Author: jares
 * @Date: 2024-02-29 16:52:48
 * @LastEditors: jares
 * @LastEditTime: 2024-02-29 17:02:14
 * @Description:
 *
 * Copyright (c) 2024 by jares, All Rights Reserved.
 */
/*
 * @Author: jares
 * @Date: 2023-08-22 10:01:37
 * @LastEditors: jares
 * @LastEditTime: 2024-02-29 16:12:06
 * @Description:
 *
 * Copyright (c) 2023 by jares, All Rights Reserved.
 */
/**
 * @description: tooltip 通用样式
 * @return {*}
 */
const init = (type) => {
	let obj = {
		trigger: type === 'pie' ? 'item' : 'axis',
		confine: true,
		axisPointer: {
			// 坐标轴指示器，坐标轴触发有效
			type: 'line' // 默认为直线，可选为：'line' | 'shadow'
		},
		borderColor: 'transparent',
		backgroundColor: 'rgba(255, 255, 255, 0.8)', // 提示框浮层的背景颜色。
		textStyle: {
			color: 'rgba(0, 0, 0, 1)',
			fontSize: 14,
			fontWeight: 'bold'
		},
		extraCssText: 'box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2), 0px 0px 5px 0px rgba(0, 0, 0, 0.1);',
		formatter: function (params) {
			// TODO 饼图不行
			let str = ''
			if (params.seriesType === 'pie') {
				str +=
					`<div style="display: flex; align-items: center;">` +
					`<span style='display:inline-block;width:8px;height:8px;border-radius:2px;background-color:${params.color};vertical-align:middle;'></span>` +
					`<span style='margin-left: 5px;'>${params.name} : ${params.value}</span>` +
					'</div>'
				// console.log(str, 'str')
			} else {
				// params[0].name表示x轴数据
				str = params[0].name
				// params是数组格式
				for (let i = 0; i < params.length; i++) {
					// 设置浮层图形的样式跟随图中展示的颜色
					const item = params[i]
					const lineBreak = i === 0 ? '<br/>' : ''
					if (item.seriesType === 'bar') {
						// TODO 柱状图块颜色不行
						// console.log(item.color, 'item')
						str +=
							`${lineBreak}<div class="PingFang-Medium"><div style="display: flex; align-items: center;">` +
							`<span style='display:inline-block;width:8px;height:8px;border-radius:2px;background-color:${item.color};vertical-align:middle;'></span>` +
							`<span style='margin-left: 5px;'>${item.seriesName} : ${item.value}</span>` +
							'</div></div>'
						// console.log(str, 'str')
					} else if (item.seriesType === 'line') {
						str +=
							'<br/>' +
							"<div class='PingFang-Medium'><span style='font-size: 33px;vertical-align: top;color:" +
							item.color +
							";'>~</span>" +
							'\t' +
							item.seriesName +
							' : ' +
							item.value +
							'</div>'
					}
				}
			}
			return str
		}
	}
	return obj
}

export default init
